package com.shoothzj.example.storage.hikari;

import com.zaxxer.hikari.HikariDataSource;
import lombok.extern.slf4j.Slf4j;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

@Slf4j
public class HikariService {
    private final HikariDataSource dataSource;

    public HikariService(HikariDataSource dataSource) {
        this.dataSource = dataSource;
    }

    public boolean selectOne() {
        try (Connection connection = dataSource.getConnection()) {
            try (Statement statement = connection.createStatement()) {
                try (ResultSet resultSet = statement.executeQuery("SELECT 1")) {
                    if (resultSet.next()) {
                        return true;
                    }
                }
            }
        } catch (SQLException e) {
            log.error("selectOne error", e);
            return false;
        }
        return false;
    }
}
